package cn.mcch.investigator.dialog;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import java.util.Arrays;

import cn.mcch.investigator.R;
import cn.mcch.investigator.adapter.base.CommonAdapter;
import cn.mcch.investigator.adapter.base.ViewHolder;
import cn.mcch.investigator.application.InvestigatorApplication;

/**
 * Created by Administrator on 2016/12/19.
 */
public class CarAreaArmyDialog extends BaseDialog implements View.OnClickListener {

    private AdapterView.OnItemClickListener l;
    private CommonAdapter adapter;
    private String[] data;
    private int numColumns;

    @Override
    protected void initEventListener() {

        ((GridView) findViewById(R.id.gv_car_area_army)).setOnItemClickListener(l);
        findViewById(R.id.close).setOnClickListener(this);
    }

    @Override
    protected View initView(LayoutInflater inflater, ViewGroup container) {
        return View.inflate(InvestigatorApplication.getInstance(), R.layout.dialog_car_area_army, null);
    }

    @Override
    public void initData() {
        ((GridView) findViewById(R.id.gv_car_area_army)).setNumColumns(numColumns);
        adapter = new CommonAdapter<String>(InvestigatorApplication.getInstance(), R.layout.list_item_car_area_army, Arrays.asList(data)) {
            @Override
            protected void convert(ViewHolder viewHolder, String item, int position) {
                viewHolder.setText(R.id.tv_car_area_army, item);
            }
        };
        setAdapterViewAdapter(R.id.gv_car_area_army, adapter);
    }

    @Override
    public void onClick(View v) {
        dismiss();
    }

    public CarAreaArmyDialog setOnItemClickListener(AdapterView.OnItemClickListener l) {
        this.l = l;
        return this;
    }


    public CarAreaArmyDialog setData(String[] data) {
        this.data = data;
        return this;

    }

    public CarAreaArmyDialog setNumColumns(int numColumns) {
        this.numColumns = numColumns;
        return this;
    }

}
